/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Manolis
 */
@Entity
@Table(name = "PURCHASE_ATTEMPTS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PurchaseAttempts.findAll", query = "SELECT p FROM PurchaseAttempts p"),
    @NamedQuery(name = "PurchaseAttempts.findByAttemptNo", query = "SELECT p FROM PurchaseAttempts p WHERE p.purchaseAttemptsPK.attemptNo = :attemptNo"),
    @NamedQuery(name = "PurchaseAttempts.findByPurchaseId", query = "SELECT p FROM PurchaseAttempts p WHERE p.purchaseAttemptsPK.purchaseId = :purchaseId"),
    @NamedQuery(name = "PurchaseAttempts.findByThreadName", query = "SELECT p FROM PurchaseAttempts p WHERE p.threadName = :threadName"),
    @NamedQuery(name = "PurchaseAttempts.findByTimeStamp", query = "SELECT p FROM PurchaseAttempts p WHERE p.timeStamp = :timeStamp")})
public class PurchaseAttempts implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PurchaseAttemptsPK purchaseAttemptsPK;
    @Basic(optional = false)
    @Column(name = "THREAD_NAME")
    private String threadName;
    @Basic(optional = false)
    @Column(name = "TIME_STAMP")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timeStamp;
    @JoinColumn(name = "PURCHASE_ID", referencedColumnName = "PURCHASE_ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Purchase purchase;

    public PurchaseAttempts() {
    }

    public PurchaseAttempts(PurchaseAttemptsPK purchaseAttemptsPK) {
        this.purchaseAttemptsPK = purchaseAttemptsPK;
    }

    public PurchaseAttempts(PurchaseAttemptsPK purchaseAttemptsPK, String threadName, Date timeStamp) {
        this.purchaseAttemptsPK = purchaseAttemptsPK;
        this.threadName = threadName;
        this.timeStamp = timeStamp;
    }

    public PurchaseAttempts(int attemptNo, int purchaseId) {
        this.purchaseAttemptsPK = new PurchaseAttemptsPK(attemptNo, purchaseId);
    }

    public PurchaseAttemptsPK getPurchaseAttemptsPK() {
        return purchaseAttemptsPK;
    }

    public void setPurchaseAttemptsPK(PurchaseAttemptsPK purchaseAttemptsPK) {
        this.purchaseAttemptsPK = purchaseAttemptsPK;
    }

    public String getThreadName() {
        return threadName;
    }

    public void setThreadName(String threadName) {
        this.threadName = threadName;
    }

    public Date getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(Date timeStamp) {
        this.timeStamp = timeStamp;
    }

    public Purchase getPurchase() {
        return purchase;
    }

    public void setPurchase(Purchase purchase) {
        this.purchase = purchase;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (purchaseAttemptsPK != null ? purchaseAttemptsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PurchaseAttempts)) {
            return false;
        }
        PurchaseAttempts other = (PurchaseAttempts) object;
        if ((this.purchaseAttemptsPK == null && other.purchaseAttemptsPK != null) || (this.purchaseAttemptsPK != null && !this.purchaseAttemptsPK.equals(other.purchaseAttemptsPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.PurchaseAttempts[ purchaseAttemptsPK=" + purchaseAttemptsPK + " ]";
    }
    
}
